package com.wang.config;

import com.alibaba.otter.canal.client.CanalConnector;
import com.alibaba.otter.canal.client.CanalConnectors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import java.net.InetSocketAddress;

@Configuration
public class CanalConfig {

    @Value("${canal.instance.host}")
    private String host;
    @Value("${canal.instance.port}")
    private Integer port;
    @Value("${canal.instance.destination}")
    private String destination;
    @Value("${canal.instance.username}")
    private String username;
    @Value("${canal.instance.password}")
    private String password;

    @Bean
    public CanalConnector getCanalConnector() {
        CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress(host,
                port), destination, username, password);
        connector.connect();
        connector.subscribe(".*\\..*");
        connector.rollback();
        return connector;
    }
}
